﻿import request from "@/utils/axios";
/**
 * 通用上传
 * @param {FormData} formData 仅需包含 key="file"
 * @param {Object} params     查询参数，如 { fileType:'01', isSecretFile:0, limitSize:1024*10 }
 * @param {{isSecretFile: boolean, fileType: number}} onProgress 上传进度回调 (percent: 0~100)
 */
export function commonUpload(formData, params = {}, onProgress) {
  return request.post("/assets-ms/file/upload", formData, {
    params,
    headers: { "Content-Type": "multipart/form-data" },
    onUploadProgress: e => {
      if (!onProgress || !e.total) return;
      const percent = Math.round((e.loaded / e.total) * 100);
      onProgress(percent);
    },
  });
}
